// pages/wode/wode.js
let util = require("../../utils/util.js");
var baseImgUrl = util.baseImgUrl;
let app=getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    networkStatus: true,
    loadingStatus: false,//默认加载完成，true--正在加载中
    loadgif: util.imgUrl + "loading.gif",//加载gif图
    loading: util.imgUrl + "loading.png",
    none_network: util.imgUrl + "none_network.png",

    topBg: "http://zhjw.youdang.xin/images/mine_top_bg.png",//顶部图片
    userlogo:baseImgUrl+"userlogo.png",//用户头像
    arrowSrc:baseImgUrl+"arrow_r_grey.png",//箭头
    navList:[{
      id:0,
      src: baseImgUrl+"wenzhang.png",
      tag:'shoucang',
      navName:"文章收藏"
    }, {
        id: 1,
        src: baseImgUrl+"daren.png",
        tag: 'daren',
        navName: "关注达人"
      }, {
        id: 2,
        src: baseImgUrl+ "zuji.png",
        tag: 'zuji',
        navName: "我的足迹"
      }, {
        id: 3,
        src: baseImgUrl+"fensi.png",
        tag: 'fensi',
        navName: "我的粉丝"
      }],
     bodyList: [{
      id: 0,
       src: baseImgUrl+"bobaohao.png",
      navName: "申请看点号"
    }, {
      id: 1,
      src: baseImgUrl+"haoyou.png",
      navName: "邀请好友"
    }, {
      id: 2,
      src: baseImgUrl+ "chengshi.png",
      navName: "申请开通城市"
    }, {
      id: 3,
      src: baseImgUrl+"xiaoxi.png",
      navName: "消息通知"
    },{
         id: 3,
         src: baseImgUrl+"huodong.png",
         navName: "同城活动"
       },]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("======================wode onload");
    var that=this;
    var nickName="";
   
    console.log(app.globalData.userInfo);

    that.setData({
      loadingStatus: true
    })

    /*********判断网络状态***************** */
    wx.getNetworkType({
      success: function (res) {
        var networkType = res.networkType;
        if (networkType == "none" || networkType == "unknown") {
          that.setData({
            networkStatus: false
          })
        } else {
          that.setData({
            networkStatus: true,
            loadingStatus: false
          })
        }
      }, fail: function (err) {
        console.log("获取网络失败" + err);
        that.setData({
          networkStatus: false
        })
      }
    })
    if (app.globalData.userInfo) {
    
      that.data.userlogo = app.globalData.userInfo.avatarUrl;
      that.data.nickName = app.globalData.userInfo.nickName;
      that.setData({
        nickName: app.globalData.userInfo.nickName,
        userlogo: app.globalData.userInfo.avatarUrl
      })
    }else{
      console.log("用户信息获取失败");
    }
    that.setData({
      loadingStatus: false
    })
    

    //测试用
    
   
    

  },



   /**********跳转到我的关注*************/ 
  myconcern:function(e){
    console.log(e);
    var that=this;
    var thisid=e.currentTarget.id;
    var tags = e.currentTarget.dataset.tags;
    wx.navigateTo({
      url: '/pages/myconcern/myconcern?thisid=' + thisid + '&tag=' + tags,
    })
    

  },

  /***********进入二级菜单*********** */
  gonext:function(e){
    var that=this;
    var thisid=e.currentTarget.id*1;
    console.log(thisid);
     switch(thisid){
       case 0:wx.navigateTo({
         url: '/pages/apply/apply',
       });break;
       case 1: wx.updateShareMenu({
         withShareTicket: true,
         success() {
           console.log("zhuanfa");
          }
       }); break;
       case 2: wx.navigateTo({
         url: '/pages/city/city',
       }); break;
       case 3: wx.navigateTo({
         url: '/pages/messages/messages',
       }); break;
       case 4: wx.navigateTo({
         url: '/pages/huodong/huodong',
       }); break;
       default:break;

     }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log("======================wode onshow");
    var that=this;
    if (app.globalData.userInfo) {
      console.log(app.globalData.userInfo);
      that.data.userlogo = app.globalData.userInfo.avatarUrl;
      that.data.nickName = app.globalData.userInfo.nickName;
    } else {
      console.log("用户信息获取失败");
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

 
  // onShareAppMessage: function (options) {
  //   var that = this;
  //   var openid = app.globalData.openid;

  //     if (res.from === 'button') {
  //       // 来自页面内转发按钮
  //       console.log(res.target)
  //     }
  //     return {
  //       title: '同城看点',
  //       path: '/pages/wode/wode',
  //       imagesUrl:"/pages/images/shareBg.png"
  //     }
    
  // }

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    var that = this;
    var openid = app.globalData.openid;

    
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    var shareObj = {
      title: "关注同城 看点生活", // 默认是小程序的名称(可以写slogan等)
      desc: "同城看点",
      path: '/pages/index/index', // 默认是当前页面，必须是以‘/’开头的完整路径
      imageUrl: '/pages/images/yaoqingBg.jpg',//图片//图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。图片长宽比是 5:4
      success: function (res) {
        // 转发成功之后的回调
        console.log("转发成功")
      },
      fail: function (res) {
        // 转发失败之后的回调
        if (res.errMsg == 'shareAppMessage:fail cancel') {
          // 用户取消转发

          console.log(options.target.dataset.id)

        } else if (res.errMsg == 'shareAppMessage:fail') {
          // 转发失败，其中 detail message 为详细失败信息
        }
      },
      complete: function () {
        // 转发结束之后的回调（转发成不成功都会执行）
      }
    };
    // 来自页面内的按钮的转发
    if (options.from == 'button') {
      var eData = options.target.dataset;

      console.log(options);
      //  内容
      shareObj.path = '/pages/index/index';

      shareObj.imageUrl = "/pages/images/yaoqingBg.jpg"

    }
    // 返回shareObj
    return shareObj;
  }
})